﻿using System;
using System.Collections.Generic;
using System.Linq;
using MRGSP.SurveyMaster.Core.Model;
using MRGSP.SurveyMaster.Core.Service;
using MRGSP.SurveyMaster.Core.Service.Utils;

namespace MRGSP.SurveyMaster.Service.Utils
{
    public class SurveyValidator : ISurveyValidator
    {
        private readonly ITreeBuilder treeBuilder;

        public SurveyValidator(ITreeBuilder treeBuilder)
        {
            this.treeBuilder = treeBuilder;
        }

        public IEnumerable<ValidationMessage> Validate(IEnumerable<Question> questions, IEnumerable<Answer> answers)
        {
            return treeBuilder.Build(questions).SelectMany(question => new QuestionValidator().Validate(question, answers));
        }
    }
}